package com.cloudsiteservice8003.controller;

import com.cloudsiteservice8003.common.Result;
import com.cloudsiteservice8003.entity.ServiceInfo;
import com.cloudsiteservice8003.entity.SiteInfo;
import com.cloudsiteservice8003.service.SiteInfoService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/siteInfo")
public class SiteInfoController {

    @Resource
    private SiteInfoService siteInfoService;

    /**
     * 获取路线基本列表
     * 分页查询
     *
     * @return
     */
    @GetMapping("/list")
    public Result list(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize,
                       @RequestParam(value = "siteCode", required = false) String siteCode) {
        return Result.success(siteInfoService.getServiceInfo(pageNum, pageSize, siteCode));
    }

    /**
     * 创建/更新路线信息
     *
     * @param
     * @return
     */
    @PostMapping(value = {"/create", "/update"})
    public Result createOrUpdate(@RequestBody SiteInfo siteInfo) {
        if (siteInfo.getId() == null) {
            siteInfoService.create(siteInfo);
            return Result.success("创建成功");
        }
        siteInfoService.updates(siteInfo);
        return Result.success("更新成功");
    }

    /**
     * 删除配送信息
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody SiteInfo SiteInfo) {
        boolean delete = siteInfoService.removeByCode(SiteInfo);
        return delete ? Result.success("删除成功") : Result.error("删除失败");
    }

}
